package ssq.gamest.toolchain;

import java.io.File
import ssq.utils.FileUtils

public class AIGenerator
{
	def String template(String weightExpression)
	'''package ssq.gamest.game.«settings.gameName».ai;

import ssq.gamest.game.ai.PokerAI;
import ssq.gamest.game.ai.PokerAiSettings;

public class «settings.gameName»AI extends PokerAI
{
    public «settings.gameName»AI(PokerAiSettings s)
    {
        super(s);
    }
    
    @Override
    protected double getTotalWeight(double sum, double hands, double residual)
    {
        return «weightExpression»;
    }
    
    @Override
    public Object act(Object status)
    {
        return null;
    }
}
'''

	GeneratorSettings settings;

	new(GeneratorSettings settings)
	{
		this.settings = settings;
	}

	def void run(String weightExpression)
	{
		if(new AIWeightExpression().test(weightExpression))
		{
			var code = template(weightExpression)

			val dir = new File(settings.genDir + settings.gameName + "/ai")
			dir.mkdirs();

			FileUtils.saveString2File(new File(dir, settings.gameName + "AI.java"), code);
		}
	}
}
